package com.shop2cn.iapi.wxcomponent.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.wxcomponent.parameter.GetMchAppTokenBean;
import com.shop2cn.iapi.wxcomponent.service.GetMchAppTokenCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.Mchapp;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
/**
*查询小程序token
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetMchAppToken{
	private static GetMchAppTokenBean getmchapptokenBean;
	private static GetMchAppTokenCall getmchapptokenCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询小程序token");
	}

	@Before
	public void caseUp() {
		getmchapptokenBean=new GetMchAppTokenBean();
		getmchapptokenCall=new GetMchAppTokenCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmchapptokenCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchAppToken_001() {
		Logger.start(true,"查询小程序token");
		try {
			DefGodMchWapper DefGodMchWapper=new DefGodMchWapper();
			Mchapp defmchapp = DefGodMchWapper.selectMchappByExample(null).get(0);

			getmchapptokenBean.setMchId(defmchapp.getMchId());
			getmchapptokenCall.setData(getmchapptokenBean);
			getmchapptokenCall.callService();			
			Logger.verifyEquals("200", getmchapptokenCall.getString("code"), "验证返回code");
			Logger.verifyEquals(defmchapp.getAccessToken(), getmchapptokenCall.getString("data"), "验证token");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetMchAppToken_002() {
		Logger.start(true,"不输入mchid失败");
		try {
			getmchapptokenCall.setData(getmchapptokenBean);
			getmchapptokenCall.callService();			
			Logger.verifyEquals("400", getmchapptokenCall.getString("code"), "验证返回code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetMchAppToken_003() {
		Logger.start(true,"输入mchid错误失败");
		try {
			getmchapptokenBean.setMchId(-1);
			getmchapptokenCall.setData(getmchapptokenBean);
			getmchapptokenCall.callService();			
			Logger.verifyEquals("400", getmchapptokenCall.getString("code"), "验证返回code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}